<template>
  <el-aside class="sideBar" :width="isCollapse ? '60px' : '200px'">
    <div class="menu-icon">
      <i class="icon iconfont icon-MENU_FOLD" @click="isCollapse = true" v-show="!isCollapse"></i>
      <i class="icon iconfont icon-MENU_FOLD" @click="isCollapse = false" v-show="isCollapse"></i>
    </div>
    <el-menu :default-active="toIndex()" :unique-opened="true" text-color="#5d6880" active-text-color="#4285f4" router :collapse="isCollapse" :collapse-transition="false">
      <el-submenu :index="index + ''" v-for="(list, index) in lists" :key="list.id">
        <template slot="title">
          <i class="icon iconfont icon-menu"></i>
          <span>{{ list.title }}</span>
        </template>
        <template v-for="item in list.children">
          <el-menu-item :index="item.index" :key="item.id" v-if="item">
            <i class="icon iconfont icon-bu-dot-circle-o"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </el-submenu>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  props: ['lists'],
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    // 根据路径绑定到对应的二级菜单，防止页面刷新重新跳回第一个
    toIndex() {
      return this.$route.path.split('/')[2];
    },
    changepath(path) { }
  },
  mounted() { }
}
</script>

<style lang="less" scoped>
.menu-icon {
  padding-left: 20px;
  width: 180px;
  height: 27px;
  line-height: 27px;
  border-bottom: 3px solid #f9f9f9;
}

.el-menu {
  border: none;
}

.icon {
  margin-right: 10px;
}

.el-menu-item {
  background-color: #f5f7fd;
}

.el-menu-item.is-active {
  background-color: #e6f3ff;
  border-right: 3px solid #58d1ff;
}
</style>

<style>
/* 点击submenu修改字体颜色，写在非scoped的style中 */
.sideBar .el-submenu.is-opened .el-submenu__title,
.sideBar .el-submenu.is-opened .icon-menu {
  color: #4285f4 !important;
}
</style>